package com.recSystem.Controller;

import com.recSystem.Entity.DTO.*;
import com.recSystem.Entity.DTO.Param.*;
import com.recSystem.Entity.POJO.HttpResponse;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.recSystem.Service.RecommendService;
import com.recSystem.Service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/user")
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
public class UserController {

    private final UserService userService;
    private final RecommendService recommendService;

    public UserController(UserService userService, RecommendService recommendService) {
        this.userService = userService;
        this.recommendService = recommendService;
    }

    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    @PostMapping("/register")
    @Operation(summary = "注册用户")
    public HttpResponse<UserRegisterDTO> addUser(@RequestBody UserRegisterParam param) {
        return userService.addUser(param);
    }

    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public HttpResponse<UserLoginDTO> loginUser(@RequestBody UserLoginParam param) {
        log.debug(param.getLogin());
        log.debug("login--" + "username:" + param.getLogin() + ",password:" + param.getPassword());
        return userService.authenticateUser(param);
    }

    @PostMapping("/info")
    @Operation(summary = "获取用户信息信息")
    public HttpResponse<DataUserDTO> getUser(@RequestHeader(value = "Authorization") String token) {
        log.debug("info--" + token);
        return userService.getUserInfo(token);
    }

    @PostMapping("/modify")
    @Operation(summary = "修改用户信息")
    public HttpResponse<DataErrorsDTO> modifyUser(@RequestBody UserModifyParam user,
                                                  @RequestHeader(value = "Authorization") String token) {
        log.debug("modify--token:{}", token);
        return userService.modifyUserInfo(user, token);
    }

    @PostMapping("/get_browsing")
    @Operation(summary = "获取用户浏览")
    public HttpResponse<UserBrowsingPageDTO> getBrowsing(@RequestBody UserBehaviorParam param,
                                                         @RequestHeader(value = "Authorization") String token) {
        return userService.getBrowsing(param, token);
    }

    @PostMapping("/get_favorite")
    @Operation(summary = "获取用户收藏")
    public HttpResponse<UserFavoritePageDTO> getFavorite(@RequestBody UserBehaviorParam param,
                                                         @RequestHeader(value = "Authorization") String token) {
        return userService.getFavorite(param, token);
    }

    @PostMapping("/logout")
    @Operation(summary = "退出登录")
    public HttpResponse userLogOut() {
        return userService.userLogOut();
    }

    @PostMapping("/change_password")
    @Operation(summary = "修改用户密码")
    public HttpResponse modifyUserPassword(@RequestBody UserChangePasswordParam param,
                                           @RequestHeader(value = "Authorization") String token) {
        return userService.modifyUserPassword(param, token);
    }

    @PostMapping("/validate_username")
    @Operation(summary = "检查用户名是否可用")
    public HttpResponse validateUsername(@RequestBody ValidateParam param) {
        return userService.validateUsername(param);
    }

    @PostMapping("/validate_email")
    @Operation(summary = "检查邮箱是否可用")
    public HttpResponse validateEmail(@RequestBody ValidateParam param) {
        return userService.validateEmail(param);
    }

    //    @PostMapping("/verify_author")
//    @Operation(summary = "作者认证")
//    public HttpResponse validateAuthor(@RequestParam("username") String username) {
//        return userService.verifyAuthor(username);
//    }

    @PostMapping("/delete_search")
    @Operation(summary = "删除检索记录")
    public HttpResponse deleteSearch(@RequestBody SearchIdParam param, @RequestHeader(value = "Authorization") String token) {
        return userService.deleteSearch(param,token);
    }

    @PostMapping("/add_search")
    @Operation(summary = "记录检索历史")
    public HttpResponse addSearch(@RequestBody UserSearchParam param, @RequestHeader(value = "Authorization") String token) {
        return userService.addSearch(param,token);
    }

    @PostMapping("/get_search")
    @Operation(summary = "获取检索历史")
    public HttpResponse<UserSearchPageDTO> getSearch(@RequestBody UserBehaviorParam param,
                                                         @RequestHeader(value = "Authorization") String token) {
        return userService.getSearch(param, token);
    }

    @PostMapping("/interest")
    @Operation(summary = "修改作者关注状态")
    public HttpResponse modifyInterest(@RequestBody AuthorInterestParam param, @RequestHeader(value = "Authorization") String token) {
        return userService.modifyInterest(param,token);
    }

    @PostMapping("/get_interest")
    @Operation(summary = "获取用户关注")
    public HttpResponse<UserInterestPageDTO> getInterest(@RequestBody UserBehaviorParam param,
                                                         @RequestHeader(value = "Authorization") String token) {
        return userService.getInterest(param, token);
    }

    @PostMapping("/get_identities")
    @Operation(summary = "获取职称信息")
    public HttpResponse<List> getIdentities() {
        return userService.getIdentities();
    }

    @PostMapping("/test")
    @Operation(summary = "联调接口测试")
    public HttpResponse test(@RequestBody int originUserId) {
        return userService.test(originUserId);
    }
}
